using DimensionsHelper.LanguageService.Symbols;
using DimensionsHelper.LanguageService.Syntax;

namespace DimensionsHelper.LanguageService;

public class AnalysisAssignment : AnalysisExpression
{
    internal AnalysisAssignment(AssignmentExpression syntaxNode, AnalysisExpression left, AnalysisExpression right,
        AnalysisNode? parent) :
        base(AnalysisBoundKinds.Assignment, syntaxNode, parent)
    {
        Syntax = syntaxNode;

        Left = left;
        Right = right;

        Left.Parent = this;
        Right.Parent = parent;
    }

    public override AssignmentExpression Syntax { get; }

    public AnalysisExpression Left { get; }

    public AnalysisExpression Right { get; }


    public override IEnumerable<AnalysisNode> GetChildren()
    {
        return [Left, Right];
    }

    internal override void AddChild(AnalysisNode child)
    {
        throw new NotSupportedException("AnalysisAssign is read-only.");
    }
}

public static partial class AnalysisNodeFactory
{
    /// <summary>
    /// 创建一个赋值表达式
    /// </summary>
    /// <param name="syntaxNode">原始的语法节点</param>
    /// <param name="left">左值表达式</param>
    /// <param name="right">右值表达式</param>
    /// <param name="parent">父节点</param>
    /// <param name="withSymbol">语法节点所在的With语句上下文类型符号</param>
    public static AnalysisAssignment Assignment(AssignmentExpression syntaxNode, AnalysisExpression left,
        AnalysisExpression right, AnalysisNode? parent, ITypeSymbol? withSymbol)
    {
        return new AnalysisAssignment(syntaxNode, left, right, parent).WithContainingWithSymbol(withSymbol);
    }
}
